package com.yanqu.road.server.logic.smallgame;

import com.yanqu.road.server.logic.smallgame.stage.GridSwitchStage;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class GridSwitchCreate {

    public static void main(String[] args) {

        int argsNum = 7;
        if (args.length < argsNum) {
            System.out.printf("need args num %d!%n", argsNum);
            return;
        }
        int length = Integer.parseInt(args[0]);
        int wide = Integer.parseInt(args[1]);
        int startKey = Integer.parseInt(args[2]);
        int blankNum = Integer.parseInt(args[3]);
        int directionNum = Integer.parseInt(args[4]);
        int haveEnd = Integer.parseInt(args[5]);
        int stageCount = Integer.parseInt(args[6]);

        if (length * wide - blankNum - 2 < 0) {
            System.out.printf("除去起点终点,空白的格子数不能超过总格子!%n");
            return;
        }

        if (length * wide - blankNum - 2 < directionNum) {
            System.out.printf("除去起点终点和空白格,有方向的格子数不能超过总格子!%n");
            return;
        }

        if (startKey != -1) {
            if (startKey / 10000 >= length || startKey % 10000 >= wide) {
                System.out.printf("指定起点不在范围内!%n");
                return;
            }
        }

        Map<String, GridSwitchStage> mapRoad = new HashMap<>();
        for (int i = 0; i < stageCount; i++) {
            GridSwitchStage stage = new GridSwitchStage(length, wide, startKey, blankNum, directionNum, haveEnd == 1);
            if (!stage.buildRandomStage()) {
                continue;
            }
            String key = stage.getStageString();
            if (!mapRoad.containsKey(key)) {
                mapRoad.put(key, stage);
            }
        }

        if(mapRoad.isEmpty()) {
            return;
        }

        StageCSVCreate.CreateGridSwitchStageConfig(new ArrayList<>(mapRoad.values()), length, wide, blankNum, directionNum, haveEnd);
    }
}
